﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../admin/assets/css/layui.css">
    <link rel="stylesheet" href="../admin/assets/css/login.css">
    <link rel="icon" href="/favicon.ico">
    <title>NBA联盟管理后台</title>
</head>
<body class="login-wrap">
<div class="login-container">
    <h3>NBA联盟管理后台</h3>
    <form class="login-form" id="form">
        <div class="input-group">
            <input type="text" id="loginName" class="input-field" name="loginName">
            <label for="loginName" class="input-label">
                <span id="namespan" class="label-title">用户名</span>
            </label>
        </div>
        <div class="input-group">
            <input type="password" id="password" class="input-field" name="password">
            <label for="password" class="input-label">
                <span id="passwordspan" class="label-title">密码</span>
            </label>
        </div>
        <button type="button" id="login" class="login-button">登录<i class="ai ai-enter"></i></button>
        <span id="button-span"></span>

    </form>
</div>
</body>

<script src="../admin/assets/layui.js"></script>
<script src="../admin/js/index.js" data-main="login"></script>
<script src="../admin/js/login.js" data-main="login"></script>
<script type="text/javascript" src="../admin/layer/jquery2.1.4.js"></script>
<script type="text/javascript" src="../admin/layer/layer.js"></script>
<script>
    $(function () {
        //登录
        $("#login").click(function () {
            //用户名验证
            let loginName = $("#loginName").val();
            if (!(/^[a-zA-Z0-9_-]{4,16}$/).test(loginName)) {
                $("#namespan").html("用户名长度4到16位（包含至少一个汉字、数字、字母、下划线)").css("color", "red");
                return false;
            } else {
                $("#namespan").html("用户名可用").css("color", "green");
            }
            //密码验证
            let password = $("#password").val();
            if (!(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/).test(password)) {
                $("#passwordspan").html("密码最少6——20位，密码至少包含 数字和英文").css("color", "red");
                return false;
            } else {
                $("#passwordspan").html("用户名可用").css("color", "green");
            }
            //加载图标设置
            let windowId = layer.load(0);
            $.ajax({
                type: "GET",
                url: "/admin/login/" + loginName + "/" + password,
                data: "",
                dataType: "json",
                success: function (vo) {
                    layer.close(windowId);
                    if (vo.code == 200) {
                        window.location.href = "/pages/index.html?roleId=" + vo.obj.roleId;
                    } else {
                        alert("登录失败！" + vo.msg);
                    }
                }
            });
        });


    });
</script>
</html>